package cn.com.headfree.rzgl.controller;

import cn.com.headfree.base.controller.ExBaseController;
import cn.com.headfree.base.controller.ResultData;
import cn.com.headfree.entity.IscUser;
import cn.com.headfree.entity.TOrgDept;
import cn.com.headfree.entity.isc.User;
import cn.com.headfree.rzgl.service.IRzglService;
import com.gta.edu.sdk.common.dto.Page;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 人资管理控制器
 *
 */
@Controller
@RequestMapping(value = "/rzgl", produces = "application/json;charset=UTF-8")
public class RzglController  extends ExBaseController {
	private static final Logger LOG = LogManager.getLogger(RzglController.class);
    @Autowired
    public IRzglService rzglService;

    /**
     * 查询人员信息
     */
    @RequestMapping("/searchUserList")
    @ResponseBody
    public ResultData searchUserList(@RequestBody IscUser iscUser, Page<IscUser> page, HttpServletRequest req) {
        ResultData result = new ResultData();
        try {
            User user = getLoginUserInfo(req);
            rzglService.searchUserList(page, iscUser, user);
            result.setData(page);
            LOG.info("查询人员信息成功");
        } catch (Exception e) {
            result.setErrorMsg("查询人员信息异常");
            result.setSuccess(false);
            LOG.error("查询人员信息异常", e);
        }
        return result;
    }

    /**
     * 查询单位树信息
     */
    @RequestMapping("/searchDeptList")
    @ResponseBody
    public ResultData searchDeptList(@RequestBody TOrgDept orgDept, HttpServletRequest req) {
        ResultData result = new ResultData();
        try {
            User user = getLoginUserInfo(req);
            List<TOrgDept> list = rzglService.searchDeptList(orgDept, user);
            result.setData(list);
            LOG.info("查询单位树信息成功");
        } catch (Exception e) {
            result.setErrorMsg("查询单位树信息异常");
            result.setSuccess(false);
            LOG.error("查询单位树信息异常", e);
        }
        return result;
    }

    /**
     * 查询单位树信息
     */
    @RequestMapping("/searchDeptByUser")
    @ResponseBody
    public ResultData searchDeptByUser(HttpServletRequest req) {
        ResultData result = new ResultData();
        try {
            User user = getLoginUserInfo(req);
            TOrgDept orgDept = new TOrgDept();
            List<TOrgDept> list = rzglService.searchDeptByUser(orgDept, user);
            result.setData(list);
            LOG.info("查询单位树信息成功");
        } catch (Exception e) {
            result.setErrorMsg("查询单位树信息异常");
            result.setSuccess(false);
            LOG.error("查询单位树信息异常", e);
        }
        return result;
    }
}
